// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   GetXml.java

package include.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import javax.servlet.ServletException;
import javax.servlet.http.*;

public class GetXml extends HttpServlet
{

	private static final String CONTENT_TYPE = "text/html; charset=UTF-8";

	public GetXml()
	{
	}

	public void init()
		throws ServletException
	{
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException
	{
		String action = request.getParameter("action");
		if (action.equals("add"))
			addXml(request, response);
	}

	protected void addXml(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException
	{
		String uniqueID = storeEmployee();
		StringBuffer xml = new StringBuffer("<result><uniqueID>");
		xml.append(uniqueID);
		xml.append("</uniqueID>");
		xml.append("<status>1</status>");
		xml.append("</result>");
		sendResponse(response, xml.toString());
	}

	private void sendResponse(HttpServletResponse response, String responseText)
		throws IOException
	{
		response.setContentType("text/xml");
		response.getWriter().write(responseText);
	}

	private String storeEmployee()
	{
		String uniqueID = "";
		Random randomizer = new Random(System.currentTimeMillis());
		for (int i = 0; i < 8; i++)
			uniqueID = (new StringBuilder(String.valueOf(uniqueID))).append(randomizer.nextInt(9)).toString();

		return uniqueID;
	}
}
